package model

import (
	"good.house/internal/constan"
	"gorm.io/gorm"
)

type ResourceData struct {
	BaseModel
	ID        int64             `json:"id" gorm:"primaryKey;autoIncrement:1000"` // 重新定义ID字段，覆盖BaseModel中的ID
	Type      constan.MediaType `json:"type" gorm:"not null;comment:资源类型"`
	Path      string            `json:"path" gorm:"not null;comment:资源路径(相对路径)"`
	PublishID int64             `json:"publishId" gorm:"not null;comment:关联的发布Id"`
}

type Publish struct {
	BaseModel
	ID             int64          `json:"id" gorm:"primaryKey;autoIncrement:1000"` // 重新定义ID字段，覆盖BaseModel中的ID
	UserId         int64          `json:"userId" gorm:"not null;comment:用户id"`
	Title          string         `json:"title" gorm:"size:50;not null;comment:标题"`
	Content        string         `json:"content" gorm:"size:500;comment:内容"`
	MonthRent      int64          `json:"monthRent" grom:"comment:月租金(厘)"`
	SeasonalRent   int64          `json:"seasonalRent" gorm:"comment:季租金(厘)"`
	HalfYearRent   int64          `json:"ha6lfYearRent" gorm:"comment:半年租金(厘)"`
	Resource       []ResourceData `json:"resource" gorm:"-"` // 不映射到数据库，即不使用外键关联
	Longitude      float32        `json:"longitude" gorm:"not nulll;comment:经度"`
	Latitude       float32        `json:"latitude" gorm:"not null;comment:纬度"`
	Address        string         `json:"address" gorm:"not null;comment:地址"`
	Tag            string         `json:"tag" gorm:"comment:标签，逗号分隔"`
	CompleteSet    string         `json:"completeSet" gorm:"comment:相关配套，逗号分隔"`
	IsShared       bool           `json:"isShared" gorm:"not null;comment:是否合租"`
	Area           float32        `json:"area" gorm:"not null;comment:房子面积"`
	Room           int            `json:"room" gorm:"not null;comment:房间数"`
	LivingRoom     int            `json:"livingRoom" gorm:"not null;comment:客厅数"`
	IsIntermediary bool           `json:"isIntermediary" gorm:"not null;comment:是否中介"`
	AgencyFee      int            `json:"agencyFee" gorm:"comment:中介费(厘)"`
}

func (p *Publish) BeforeCreate(db *gorm.DB) error {
	return nil
}

func (p *Publish) AfterCreate(db *gorm.DB) error {
	return nil
}
